home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / oldwish / RCS / wishScroll.c,v < prev    next >
Encoding:
Text File  |  1989-07-13  |  9.6 KB  |  377 lines

  1. head     1.3;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    mgbaker:1.3; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.3
  10. date     89.01.11.11.58.35;  author mlgray;  state Exp;
  11. branches ;
  12. next     1.2;
  13.  
  14. 1.2
  15. date     88.11.02.14.50.55;  author mlgray;  state Exp;
  16. branches ;
  17. next     1.1;
  18.  
  19. 1.1
  20. date     88.10.03.12.48.30;  author mlgray;  state Exp;
  21. branches ;
  22. next     ;
  23.  
  24.  
  25. desc
  26. @X11: works pretty much now.
  27. @
  28.  
  29.  
  30. 1.3
  31. log
  32. @Temporary checkin
  33. @
  34. text
  35. @/* 
  36.  * WishScroll.c --
  37.  *
  38.  *    Routines for dealing with scrolling.
  39.  *
  40.  * Copyright 1987 Regents of the University of California
  41.  * All rights reserved.
  42.  * Permission to use, copy, modify, and distribute this
  43.  * software and its documentation for any purpose and without
  44.  * fee is hereby granted, provided that the above copyright
  45.  * notice appear in all copies.  The University of California
  46.  * makes no representations about the suitability of this
  47.  * software for any purpose.  It is provided "as is" without
  48.  * express or implied warranty.
  49.  */
  50.  
  51. #ifndef lint
  52. static char rcsid[] = "$Header: /a/newcmds/wish/RCS/wishScroll.c,v 1.2 88/11/02 14:50:55 mlgray Exp Locker: mlgray $ SPRITE (Berkeley)";
  53. #endif not lint
  54.  
  55.  
  56. #include "string.h"
  57. #include "sx.h"
  58. #include "wishInt.h"
  59.  
  60. /* This is global for now but will go into WishWindow structure... */
  61. extern    int    wishNumGroupsToHide;
  62. extern    Boolean    wishSkipEmptyGroupsP;
  63.  
  64.  
  65. /*
  66.  *----------------------------------------------------------------------
  67.  *
  68.  * WishScroll --
  69.  *
  70.  *    Scrollbar call-back routine.
  71.  *
  72.  * Results:
  73.  *    None.
  74.  *
  75.  * Side effects:
  76.  *    The display may scroll.
  77.  *
  78.  *----------------------------------------------------------------------
  79.  */
  80. void
  81. WishScroll(clientData, distance, units, window)
  82.     ClientData    clientData;
  83.     float    distance;
  84.     int        units;    /*  SX_SCROLL_ABSOLUTE or ..._PAGES */
  85.     Window    window;
  86. {
  87.     float    top, bottom;
  88.     float    newTop, newBottom;
  89.     WishWindow    *aWindow;
  90.     float    displayCover;        
  91.     int        oldFirstElement;
  92.     int        newLastElement;
  93.     int        numDisplayed;
  94.     int        numCouldDisplay;
  95.  
  96.     aWindow = (WishWindow *) clientData;
  97.  
  98. #ifdef SCROLL_DEBUG
  99.     fprintf(stderr, "Entered WishScroll:\n");
  100.     fprintf(stderr, "\tdistance is %f\n", distance);
  101.     fprintf(stderr, "\tunits is %s\n", units == SX_SCROLL_PAGES ?
  102.         "scroll_pages" : "scroll_absolute");
  103.     fprintf(stderr, "\tfirstElement is %d\n",
  104.         aWindow->firstElement);
  105.     fprintf(stderr, "\tlastElement is %d\n",
  106.         aWindow->lastElement);
  107.     fprintf(stderr, "\tnumElements is %d\n",
  108.         aWindow->numElements);
  109.     fprintf(stderr, "\tnumGroups is %d\n",
  110.         aWindow->numGroups);
  111. #endif SCROLL_DEBUG
  112.  
  113.     oldFirstElement = aWindow->firstElement;    /* save to compare */
  114.     numCouldDisplay = aWindow->numRows * (aWindow->usedCol + 1);
  115.     numDisplayed = aWindow->lastElement - aWindow->firstElement + 1;
  116.  
  117.     if (units == SX_SCROLL_PAGES) {
  118.     /*
  119.      * If we're supposed to scroll forwards, check to see if the end of
  120.      * the display has already been reached.
  121.      */
  122.     if (distance > 0 && (numDisplayed < numCouldDisplay ||
  123.         aWindow->lastElement >= aWindow->totalDisplayEntries)) {
  124.         return;    /* No point -- already hit end of display */
  125.     }
  126.     aWindow->firstElement += distance * numCouldDisplay;
  127.     /* no point in scrolling so that we waste space in last column */
  128.     if (aWindow->firstElement + numCouldDisplay - 1 >
  129.         aWindow->totalDisplayEntries) {
  130.         aWindow->firstElement = aWindow->totalDisplayEntries -
  131.             numCouldDisplay + 1;
  132.     }
  133.     /* The lowest numbered element that makes sense is number 1 */
  134.     if (aWindow->firstElement < 1) {
  135.         aWindow->firstElement = 1;
  136.     }
  137.     if (aWindow->firstElement == oldFirstElement) {
  138.         return;    /* no change */
  139.     }
  140.     newLastElement = aWindow->firstElement + numCouldDisplay - 1;
  141.  
  142. #ifdef SCROLL_DEBUG
  143.     fprintf(stderr,
  144.         "WishScroll dealing with page scrolling:\n");
  145.     fprintf(stderr, "\tfirstElement is %d\n",
  146.         aWindow->firstElement);
  147.     fprintf(stderr, "\tnewLastElement is %d\n",
  148.         newLastElement);
  149.     fprintf(stderr, "\tcalling SetPositions and Redraw\n");
  150. #endif SCROLL_DEBUG
  151.  
  152.     /* scroll */
  153.     WishSetPositions(aWindow);
  154.     /*
  155.      * WishRedraw will be called from event caused in
  156.      * WishSetPositions().
  157.      */
  158.  
  159. #ifdef SCROLL_DEBUG
  160.     {
  161.         float    a, b;
  162.  
  163.         fprintf(stderr,
  164.             "End of WishScroll dealing with page scrolling:\n");
  165.         fprintf(stderr, "\tfirstElement is %d\n",
  166.             aWindow->firstElement);
  167.         fprintf(stderr, "\tlastElement is %d\n",
  168.             aWindow->lastElement);
  169.         Sx_ScrollbarGetRange(wishDisplay, window, &a, &b);
  170.         fprintf(stderr, "\ttop is now %f\n", a);
  171.         fprintf(stderr, "\tbottom is now %f\n", b);
  172.     }
  173. #endif SCROLL_DEBUG
  174.  
  175.     return;
  176.     }
  177.     if (units != SX_SCROLL_ABSOLUTE) {
  178.     Sx_Panic(wishDisplay,
  179.         "In WishScroll(): Unknown scrolling method requested.");
  180.     }
  181.     /* SX_SCROLL_ABSOLUTE from here on */
  182.  
  183.     Sx_ScrollbarGetRange(wishDisplay, window, &top, &bottom);
  184.  
  185. #ifdef SCROLL_DEBUG
  186.     fprintf(stderr, "\tbefore scrolling, top is %f\n", top);
  187.     fprintf(stderr, "\tbefore scrolling, bottom is %f\n", bottom);
  188. #endif SCROLL_DEBUG
  189.  
  190.     if (aWindow->numElements <= 0) {
  191.     displayCover = 1.0;
  192.     } else {
  193.     /* The portion of the total entries that can be visible. */
  194.     displayCover = ((float) numCouldDisplay) /
  195.         ((float) aWindow->totalDisplayEntries);
  196.     if (displayCover > 1.0) {
  197.         displayCover = 1.0;     /* can't cover more than all of it */
  198.     }
  199.     }
  200. #ifdef SCROLL_DEBUG
  201.     fprintf(stderr, "\tdisplayCover is %f\n", displayCover);
  202. #endif SCROLL_DEBUG
  203.  
  204.     newTop = distance - (displayCover / 2.0);
  205.     newBottom = distance + (displayCover / 2.0);
  206.     if (newTop < 0) {
  207.     newTop = 0.0;
  208.     newBottom = displayCover;
  209.     }
  210.     if (newBottom > 1.0) {
  211.     newBottom = 1.0;
  212.     newTop = 1.0 - displayCover;
  213.     }
  214.     if (newTop == top && newBottom == bottom) {
  215.     return;        /* no change */
  216.     }
  217.     /*
  218.      * I set firstElement from newTop unless newBottom happens to be
  219.      * the very end.  If so, I make sure that the last element should
  220.      * be visible to avoid roundoff errors.
  221.      */
  222.     if (newBottom == 1.0) {
  223.     newLastElement = aWindow->totalDisplayEntries;
  224.     aWindow->firstElement = aWindow->totalDisplayEntries -
  225.         numCouldDisplay + 1;
  226.     /*
  227.      * If there are fewer things to display than there are spaces,
  228.      * the above would leave firstElement < 0.  The lowest element
  229.      * we can start displaying is the first element.  (firstElement
  230.      * is incremented below by one.)
  231.      */
  232.     if (aWindow->firstElement < 1) {
  233.         aWindow->firstElement = 1;
  234.     }
  235.     } else {
  236.     aWindow->firstElement =
  237.         (int) (newTop * aWindow->totalDisplayEntries) + 1;
  238. #ifdef NOTDEF
  239.     /* this seems not to be necessary */
  240.     newLastElement = aWindow->firstElement + numCouldDisplay - 1;
  241. #endif NOTDEF
  242.     }
  243. #ifdef SCROLL_DEBUG
  244.     fprintf(stderr, "In WishScroll, after calculations:\n");
  245.     fprintf(stderr, "\tfirstElement is %d\n",
  246.         aWindow->firstElement);
  247.     fprintf(stderr, "\tnewLastElement is %d\n",
  248.         newLastElement);
  249.     fprintf(stderr, "\tnewTop is %f\n", newTop);
  250.     fprintf(stderr, "\tnewBottom is %f\n", newBottom);
  251.     fprintf(stderr,
  252.         "\tcalling WishSetPositions, then WishRedraw\n");
  253. #endif SCROLL_DEBUG
  254.     if (oldFirstElement == aWindow->firstElement) {
  255.     return;        /* no change */
  256.     }
  257.  
  258.     WishSetPositions(aWindow);
  259.  
  260.     /* Things are where we want them.  WishRedraw() should be called
  261.      * as a result of an event caused in WishSetPositions.  WishRedraw()
  262.      * will call SetRange again...  Go scroll.
  263.      */
  264.     
  265. #ifdef SCROLL_DEBUG
  266.     {
  267.     float    a, b;
  268.  
  269.     Sx_ScrollbarGetRange(wishDisplay, window, &a, &b);
  270.     fprintf(stderr, "At end of WishScroll:\n");
  271.     fprintf(stderr, "\tnewTop was supposed to be %f\n", newTop);
  272.     fprintf(stderr, "\tnewBottom was supposed to be %f\n",
  273.         newBottom);
  274.     fprintf(stderr, "\tRedraw called SetRange and:\n");
  275.     fprintf(stderr, "\ttop is really %f\n", a);
  276.     fprintf(stderr, "\tbottom is really %f\n", b);
  277.     fprintf(stderr, "\tfirstElement is %d\n",
  278.         aWindow->firstElement);
  279.     fprintf(stderr, "\tlastElement is %d\n",
  280.         aWindow->lastElement);
  281.     fprintf(stderr, "\tnumElements is %d\n",
  282.         aWindow->numElements);
  283.     }
  284. #endif SCROLL_DEBUG
  285.  
  286.     return;
  287. }
  288. @
  289.  
  290.  
  291. 1.2
  292. log
  293. @fsflat changed to wish
  294. @
  295. text
  296. @d18 1
  297. a18 1
  298. static char rcsid[] = "$Header: wishScroll.c,v 1.1 88/10/03 12:48:30 mlgray Exp $ SPRITE (Berkeley)";
  299. @
  300.  
  301.  
  302. 1.1
  303. log
  304. @Initial revision
  305. @
  306. text
  307. @d2 1
  308. a2 1
  309.  * FsflatScroll.c --
  310. d18 1
  311. a18 1
  312. static char rcsid[] = "$Header: fsflatScroll.c,v 1.10 88/06/10 13:15:22 mlgray Exp $ SPRITE (Berkeley)";
  313. d24 1
  314. a24 1
  315. #include "fsflatInt.h"
  316. d26 3
  317. a28 3
  318. /* This is global for now but will go into FsflatWindow structure... */
  319. extern    int    fsflatNumGroupsToHide;
  320. extern    Boolean    fsflatSkipEmptyGroupsP;
  321. d34 1
  322. a34 1
  323.  * FsflatScroll --
  324. d47 1
  325. a47 1
  326. FsflatScroll(clientData, distance, units, window)
  327. d55 1
  328. a55 1
  329.     FsflatWindow    *aWindow;
  330. d62 1
  331. a62 1
  332.     aWindow = (FsflatWindow *) clientData;
  333. d65 1
  334. a65 1
  335.     fprintf(stderr, "Entered FsflatScroll:\n");
  336. d110 1
  337. a110 1
  338.         "FsflatScroll dealing with page scrolling:\n");
  339. d119 1
  340. a119 1
  341.     FsflatSetPositions(aWindow);
  342. d121 2
  343. a122 2
  344.      * FsflatRedraw will be called from event caused in
  345.      * FsflatSetPositions().
  346. d130 1
  347. a130 1
  348.             "End of FsflatScroll dealing with page scrolling:\n");
  349. d135 1
  350. a135 1
  351.         Sx_ScrollbarGetRange(fsflatDisplay, window, &a, &b);
  352. d144 2
  353. a145 2
  354.     Sx_Panic(fsflatDisplay,
  355.         "In FsflatScroll(): Unknown scrolling method requested.");
  356. d149 1
  357. a149 1
  358.     Sx_ScrollbarGetRange(fsflatDisplay, window, &top, &bottom);
  359. d210 1
  360. a210 1
  361.     fprintf(stderr, "In FsflatScroll, after calculations:\n");
  362. d218 1
  363. a218 1
  364.         "\tcalling FsflatSetPositions, then FsflatRedraw\n");
  365. d224 1
  366. a224 1
  367.     FsflatSetPositions(aWindow);
  368. d226 2
  369. a227 2
  370.     /* Things are where we want them.  FsflatRedraw() should be called
  371.      * as a result of an event caused in FsflatSetPositions.  FsflatRedraw()
  372. d235 2
  373. a236 2
  374.     Sx_ScrollbarGetRange(fsflatDisplay, window, &a, &b);
  375.     fprintf(stderr, "At end of FsflatScroll:\n");
  376. @
  377.